package com.qing.picture.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class FileController {

//    @Autowired
//    private AliyunOssUtil aliyunOssUtil;


//    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
//    @PostMapping("/upload")
//    public BaseResponse<String> uploadFile(@RequestParam("file") MultipartFile file) {
//        String filepath =  aliyunOssUtil.uploadFile(file);
//        return ResultUtils.success(filepath);
//    }
//    /**
//     * 测试文件下载
//     *
//     * @param filepath 文件路径
//     * @param response 响应对象
//     */
//    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
//    @GetMapping("/download/")
//    public void testDownloadFile(@RequestParam(value = "filepath") String filepath, HttpServletResponse response) throws IOException {
//        // 设置响应头
//        response.setContentType("application/octet-stream;");
//        response.setHeader("Content-Disposition", "attachment; filename=" + filepath);
//        // 下载文件
//            OSSObject ossObject = aliyunOssUtil.downloadFile(filepath);
//            // 获取文件输入流
//            InputStream inputStream = ossObject.getObjectContent();
//        // 获取响应输出流
//        OutputStream outputStream = response.getOutputStream();
//
//        // 缓冲区大小
//        byte[] buffer = new byte[4096];
//        int bytesRead;
//        while ((bytesRead = inputStream.read(buffer)) != -1) {
//            outputStream.write(buffer, 0, bytesRead);
//        }
//        outputStream.flush();
//        outputStream.close();
//    }
}
